package com.huatec.hiot_cloud.core.service.impl;

import com.huatec.hiot_cloud.core.dao.DeviceDao;
import com.huatec.hiot_cloud.core.dao.UserDao;
import com.huatec.hiot_cloud.core.entity.Device;
import com.huatec.hiot_cloud.core.entity.User;
import com.huatec.hiot_cloud.core.service.IDeviceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class DeviceServiceImpl implements IDeviceService {
    @Autowired
    private DeviceDao deviceDao;
    @Autowired
    private UserDao userDao;

    @Override
    public int addDevice(Device device) {
        device.setCreated(new Date());
        device.setUpdated(new Date());
        User user = userDao.findById("id");
        device.setUser_id(user.getId());
        return deviceDao.insertDevice(device);
    }

    @Override
    public int delDeviceById(Device device) {
        return deviceDao.delDeviceById(device);
    }

    @Override
    public int updateDeviceById(Device device) {
        device.setUpdated(new Date());
        return deviceDao.updateDeviceById(device);
    }

    @Override
    public List<Device> getDeviceList(Device device) {
        return deviceDao.getDeviceListByDevice(device);
    }
}
